package com.zhuchaooasystem.widget;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;

import com.zhuchaooasystem.R;


/**
 * Created by yinsi on 2016/5/25.
 */
public class CameraPickDialog extends Dialog implements View.OnClickListener {

    private Button btn_camera;
    private Button btn_album;
    private Button btn_cancel;
    //----
    private Context context;
    private Window window;
    //----
    private onViewClickListenner listenner;

    public CameraPickDialog(Context context) {
        this(context, R.style.dialog_camera_pick_style);
        this.context = context;
    }

    public CameraPickDialog(Context context, int themeResId) {
        super(context, R.style.dialog_camera_pick_style);
        this.context = context;
    }

    protected CameraPickDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        this.context = context;
    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dlg_camera_pick);
        //----
        btn_camera = (Button) findViewById(R.id.dlg_camera_pick_btn_camera);
        btn_album = (Button) findViewById(R.id.dlg_camera_pick_btn_album);
        btn_cancel = (Button) findViewById(R.id.dlg_camera_pick_btn_cancel);
        btn_camera.setOnClickListener(this);
        btn_album.setOnClickListener(this);
        btn_cancel.setOnClickListener(this);
        window = getWindow();
        // 设置显示动画
        window.setWindowAnimations(R.style.dialog_camera_pick_anim);
        WindowManager.LayoutParams wl = window.getAttributes();
        wl.x = 0;
        wl.y = ((Activity) context).getWindowManager().getDefaultDisplay().getHeight();
        // 以下这两句是为了保证按钮可以水平满屏
        wl.width = ViewGroup.LayoutParams.MATCH_PARENT;
        wl.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        // 设置显示位置
        onWindowAttributesChanged(wl);
        // 设置点击外围
        setCanceledOnTouchOutside(true);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            //拍照按钮
            case R.id.dlg_camera_pick_btn_camera:
                if (listenner != null) {
                    listenner.onCamera(CameraPickDialog.this);
                } else {
                    dismiss();
                }
                break;
            //本地上传按钮
            case R.id.dlg_camera_pick_btn_album:
                if (listenner != null) {
                    listenner.onAlbum(CameraPickDialog.this);
                } else {
                    dismiss();
                }
                break;
            //取消按钮
            case R.id.dlg_camera_pick_btn_cancel:
                dismiss();
                break;
        }
    }

    public interface onViewClickListenner {
        void onCamera(CameraPickDialog dialog);
        void onAlbum(CameraPickDialog dialog);
    }

    public void setOnViewClickListener(onViewClickListenner listener) {
        listenner = listener;
    }


}
